package com.cincc.cinccimdemo.ui.conversation.sharefile;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.cincc.im.callback.ImCallback;
import com.cincc.im.core.IMSipPhoneCtrl;
import com.cincc.im.model.ImResponse;
import com.cincc.im.model.dbmodel.ConversationInfo;
import com.cincc.im.table.IMGroupFile;
import com.cincc.im.util.ImManager;

import java.util.List;

public class GroupShareFileViewModel extends ViewModel {
    private MutableLiveData<List<IMGroupFile>> shareFileListLiveData;

    public MutableLiveData<List<IMGroupFile>> shareFileListLiveData(String groupId) {
        if (shareFileListLiveData == null) {
            shareFileListLiveData = new MutableLiveData<>();
        }
        ImManager.getInstance().getWorkHandler().post(() -> {
            IMSipPhoneCtrl.getInstance().getGroupShareFileList(groupId, 0, new ImCallback() {
                @Override
                public void callback(ImResponse imResponse) {
                    if (imResponse.getCode() == 0) {
                        List<IMGroupFile> list = (List<IMGroupFile>) imResponse.getData();
                        shareFileListLiveData.postValue(list);
                    }
                }
            });
        });
        return shareFileListLiveData;
    }

    public void reloadConversationList(String groupId) {
        if (shareFileListLiveData == null) {
            return;
        }
        ImManager.getInstance().getWorkHandler().post(() -> {
            IMSipPhoneCtrl.getInstance().getGroupShareFileList(groupId, 0, new ImCallback() {
                @Override
                public void callback(ImResponse imResponse) {
                    if (imResponse.getCode() == 0) {
                        List<IMGroupFile> list = (List<IMGroupFile>) imResponse.getData();
                        shareFileListLiveData.postValue(list);
                    }
                }
            });
        });
    }
}
